package com.wjs.blog.controller;

import com.wjs.blog.common.aop.Cache;
import com.wjs.blog.common.aop.LogAnnotation;
import com.wjs.blog.service.ArticleService;
import com.wjs.blog.vo.Result;
import com.wjs.blog.vo.parms.ArticleParms;
import com.wjs.blog.vo.parms.PageParms;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/articles")
public class ArticleControl {
    @Autowired
    ArticleService articleService;
    /**
     * 首页文章列表
     * @param pageParms
     */
    @PostMapping
    @LogAnnotation(module="文章",operater="获取文章列表")
    @Cache(expire = 5 * 60 * 1000,name = "listArticle")
    public Result listArticle(@RequestBody PageParms pageParms) {
        return articleService.listArticle(pageParms);
    }

    /**
     * 首页最热文章
     * @return
     */
    @PostMapping("/hot")
    @Cache(expire = 5 * 60 * 1000,name = "hot_article")
    public Result HotArticle() {
        int limit=5;
        return articleService.HotArticle(limit);
    }
    /**
     * 首页最新文章
     * @return
     */
    @PostMapping("/new")
    @Cache(expire = 5 * 60 * 1000,name = "new_article")
    public Result NewArticle() {
        int limit=5;
        return articleService.NewArticle(limit);
    }
    /**
     * 文章归档
     * @return
     */
    @PostMapping("/listArchives")
    public Result listArchives() {
        return articleService.listArchives();
    }

    @PostMapping("view/{id}")
    public Result findArticleById(@PathVariable("id") long id){
        System.out.println(id);

        return articleService.findArticleById(id);
    }
    @PostMapping("/publish")
    public Result publish(@RequestBody ArticleParms articleParam){
        return articleService.publish(articleParam);
    }
}
